﻿using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using MiniFox.Components;
using MiniFox.Components.Configurations;
using MiniFox.Configurations;

namespace MiniFox.Web
{
    /// <summary>
    /// 
    /// </summary>
    public interface IWebHostFactory
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        IWebHost CreateWebHost(params string[] args);
    }

    internal class DefaultWebHostFactory : IWebHostFactory
    {
        public virtual IWebHost CreateWebHost(params string[] args)
        {
            var builder = WebHost.CreateDefaultBuilder(args);
            string currentDir = Environment.CurrentDirectory;
            builder.UseContentRoot(currentDir);
            HostingStartup hostingStartup = new HostingStartup();
            hostingStartup.Configure(builder);
            var host = builder.Build();
            return host;
        }
    }
}
